import config from './config';
export default (url, data = {}, method = 'GET') => {
	return new Promise((resolve, reject) => {
		// 1.初始化Promise实例的状态为pending
		// 2.执行异步任务
		wx.request({
			url: config.host + url,
			data,
			method,
			header: {
				cookie: wx.getStorageSync('cookie').toString(),
			},
			success: (res) => {
				if (data.isLogin) {
					// 将cookies保存至本地
					wx.setStorageSync('cookie', res.cookies);
				}
				// 3. 修改Promise实例的状态为成功状态 resolve
				resolve(res.data);
			},
			fail: (err) => {
				// 3. 修改Promise实例的状态为失败状态 reject
				reject(err);
			},
		});
	});
};
